﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GBMS.DAL;
using KPIS.GERP.GBMS.MODEL;
using KPIS.GERP.GBMS.DALFactory;
using KPIS.GERP.GBMS.IBLL;

namespace KPIS.GERP.GBMS.BLL
{
    public class OptionBLL : IOptionBLL
    {
        private static readonly IOptionDAL dal = DataAccess.CreateOptionList();
        private OptionTypeInfo optTypeInfo = new OptionTypeInfo();
        private OptionInfo optParent = new OptionInfo();

        public OptionBLL()
        {

        }

        public void Insert(string code, string name, string descr, int parent, int type, Nullable<int> year)
        {
            optParent.Sequence = parent;

            int chkError = dal.Insert(new OptionInfo(0, code, name, descr, "", type, year, optParent, new UserRecordInfo(1, null)));

            if (chkError == 0)
            {
                // Error
            }
        }

        public void Update(int seq, string code, string name, string descr, int parent, int type)
        {
            optParent.Sequence = parent;

            int chkError = dal.Update(new OptionInfo(seq, code, name, descr, "", type, null, optParent, null));

            if (chkError == 0)
            {
                // Error
            }
        }

        public void Delete(int seq)
        {
            int chkError = dal.Delete(seq);
        }

        public IList<OptionInfo> Search(int seq, int type, Nullable<int> year)
        {
            return Search(seq, "", "", "", 0, type, year);
        }

        public IList<OptionInfo> Search(int seq, string code, string name, string descr, int parent, int type, Nullable<int> year)
        {
            optParent.Sequence = parent;
                
            return dal.Search(new OptionInfo(seq, code, name, descr, "", type, year, optParent, null));
        }

        public IList<TreeViewInfo> TreeView(int type)
        {
            return dal.TreeView(type);
        }

        public bool CheckDuplicateCode(string code)
        {
            return dal.CheckDuplicateCode(code, null);
        }
        public bool CheckDuplicateCode(string code, string sequence)
        {
            return dal.CheckDuplicateCode(code, sequence);
        }
    }
}
